package com.xp.tinyurl.service;

import com.xp.tinyurl.model.Statistics;
import com.xp.tinyurl.dao.StatisticsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

/**
 * @author liuxw
 * @date 2019/3/28
 * @since 1.0
 */
@Service
public class StatisticsService {

    @Autowired
    private StatisticsDao statisticsDao;

    public int persistentByMinute(List<Statistics> statistics) {
        return statisticsDao.insertList(statistics);
    }

    public List<Statistics> getMinuteStatisticsByAppKey(Map map) {
        Example example = new Example(Statistics.class);
        Example.Criteria criteria = example.createCriteria();
        if(map.containsKey("appKey")){
            criteria.andEqualTo("appKey",map.get("appKey"));
        }
        if(map.containsKey("startTime") && map.containsKey("endTime")){
            criteria.andBetween("statistics_time",map.get("startTime"),map.get("endTime"));
        }

        return statisticsDao.selectByExample(example);
    }
}
